



import 'dart:math';
import 'dart:ui';

import 'package:bt_tool/basic/bt_date_tool.dart';
import 'package:bt_tool/basic/bt_model.dart';
import 'package:flutter/material.dart';

import '../../../common/config/app_theme_color_config.dart';
import '../do_next_define.dart';



class DoNextModel extends BTModel{

  int id = 0;
  String content = "";
  int startTime = 0;
  int createTime = 0;
  int status = 0; //DoNextMainMenuAction
  int endTime = 0;
  int isDel = 0; //0:未删除；1：已删除
  bool isSelect = false;
  int pid = 0;
  String projectName = "";

  DoNextModel(super.oriJsonData);

  @override
  void parse(){
    id = jsonTool.getInt("id");
    content = jsonTool.getString("content");
    startTime = jsonTool.getInt("startTime");
    createTime = jsonTool.getInt("createTime");
    status = jsonTool.getInt("status");
    endTime = jsonTool.getInt("endTime");
    isDel = jsonTool.getInt("isDel");
    pid = jsonTool.getInt("pid");
    projectName = jsonTool.getString("projectName");
  }

  @override
  Map<String,dynamic> convertToDict(){
    var dict = super.convertToDict();
    dict["id"] = id;
    dict["content"] = content;
    dict["startTime"] = startTime;
    dict["createTime"] = createTime;
    dict["status"] = status;
    dict["endTime"] = endTime;
    dict["isDel"] = isDel;
    dict["pid"] = pid;
    dict["projectName"] = projectName;
    return dict;
  }

  String getTimeStr(){
    DateTime startTime = BTDateTool.fromSeconds(this.startTime);
    DateTime endTime = BTDateTool.fromSeconds(this.endTime);
    
    if(BTDateTool.isSameDay(startTime, endTime)){
      return "${BTDateTool.formatter(BTDateTool.MMDDHHmm, startTime)} - ${BTDateTool.formatter(BTDateTool.HHmm, endTime)}";
    }
    
    if(BTDateTool.isSameMonth(startTime, endTime)){
      return "${BTDateTool.formatter(BTDateTool.MMDDHHmm, startTime)} - ${BTDateTool.formatter(BTDateTool.MMDDHHmm, endTime)}";
    }

    if(BTDateTool.isSameYear(startTime, endTime)){
      return "${BTDateTool.formatter(BTDateTool.MMDDHHmm, startTime)} - ${BTDateTool.formatter(BTDateTool.MMDDHHmm, endTime)}";
    }

    return "${BTDateTool.formatter(BTDateTool.YYYYMMDDHHmmss, startTime)} - ${BTDateTool.formatter(BTDateTool.YYYYMMDDHHmmss, endTime)}";
  }
  
  String getStatusStr(){
    if(status == DoNextStatus.finish.iValue){
      return "已完成";
    }
    
    if(endTime < BTDateTool.currentTimeSeconds()){
      return "已超时";
    }

    return "进行中";
  }

  bool isOutTime(){
    return endTime < BTDateTool.currentTimeSeconds();
  }

  Color statusTextColor(){
    if(status == DoNextStatus.finish.iValue){
      return Colors.green;
    }

    if(isOutTime()){
      return Colors.red;
    }

    return AppThemeColor.textColor;

  }
    
}


class DoNextGroupModel extends BTModel{
  String title = "";
  List<DoNextModel> list = [];
  int pid = 0;
  int index = 1;

  DoNextGroupModel(super.oriJsonData);
  


}